package com.wx.activitys.base.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wx.activitys.base.utils.VerifyCodeUtils;


@Controller
public class ValidateCodeController {
	
	@RequestMapping(value="/validate/validateCode")
	@ResponseBody
	public String validateCode(HttpServletRequest request,HttpServletResponse response) throws Exception{  
	    // 设置响应的类型格式为图片格式  
	    response.setContentType("image/jpeg");  
	    //禁止图像缓存。  
	    response.setHeader("Pragma", "no-cache");  
	    response.setHeader("Cache-Control", "no-cache");
	    response.setDateHeader("Expires", 0);  
	  
	    HttpSession session = request.getSession();  
	    //新的二维码
	    String verifyCode = VerifyCodeUtils.generateVerifyCode(4); 
	    VerifyCodeUtils.outputImage(70, 30, response.getOutputStream(), verifyCode);
	    //ValidateCode vCode = new ValidateCode(70,40,4,50);
	    session.setAttribute("code", verifyCode);  
	    //vCode.write(response.getOutputStream());  
	    return null;  
	}
	
	@RequestMapping(value="/validate")  
	public String page(HttpServletRequest request,HttpServletResponse response) throws Exception{  
	    
	    return "page";
	}
	
}
